import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

import routes from '@/views/'
var router=new VueRouter({
    routes:[...routes,
    {path:'/*',redirect:'/'}],

})
//全局路由守卫
//把路由匹配的过程变成几个钩子函数beforeEach是在匹配之前(比较常用)
//next一条逻辑线路,只能执行一次
router.beforeEach((to,from,next)=>{
    //判断是否需要权限
    if(to.meta.isAuth){
        //判断是否登录
        if(localStorage.getItem('token')){
            next()
        }else{
            next('/login')
        }
    }
    next()
})

export default router